#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>

int			g_chile_stop = 0;  //子进程停止控制
int			g_parent_run = 0;  //父进程运行控制

void sig_chile(int signum)
{
	if(SIGUSR1 == signum)
	{
		g_chile_stop = 1;
	}
}

void sig_parent(int signum)
{
	if(SIGUSR2 == signum)
	{
		g_parent_run = 1;
	}
}

int main(int argc, char **argv)
{
	int					pid = -1;
	int					rv = -1;
	int					staloc;

	signal(SIGUSR1, sig_chile);
	signal(SIGUSR2, sig_parent);

	pid = fork();

	if(pid < 0)
	{
		printf(" fork error : %s \n",strerror(errno));
		return -1;
	}
	else if(pid == 0)
	{
		printf(" chile ok \n" );

		kill(getppid(),SIGUSR2);

		while(!g_chile_stop)
		{
			printf(" chile wait \n");
			sleep(1);
		}

		printf(" chile run \n");

		return 0;
	}
	
	while( !g_parent_run)
	{		
		printf("parent wait \n");
		sleep(1);
	}

	printf("parent run\n");

	kill(pid, SIGUSR1);

	wait(&staloc);

	return 0;
}





